/*
 * CommonResource.h
 *
 *  Created on: 2013. 9. 5.
 *      Author: mega@gamevil.com
 */

#ifndef COMMONRESOURCE_H_
#define COMMONRESOURCE_H_

#include <map>

namespace ProjectZ { namespace NResource {

class CommonData
{
public:
	struct Key
	{
		Key() : type(0), sub_type(0) {}
		Key(int rType, int rSubType) : type(rType), sub_type(rSubType) {}

		int type;
		int sub_type;

		bool operator == (const Key & rSide) const
		{
			if (this->type == rSide.type && this->sub_type == rSide.sub_type)
				return true;

			return false;
		}

		bool operator < (const Key & rSide) const
		{
			if (this->type < rSide.type)
			{
				return true;
			}
			else if (this->type == rSide.type)
			{
				if (this->sub_type < rSide.sub_type)
					return true;
			}

			return false;
		}
	};

public:
	struct Flyweight
	{
		int _TYPE;
		int _SUB_TYPE;
		int _VALUE1;
		int _VALUE2;
	};

public:
	CommonData() {};
	virtual ~CommonData();

	bool LoadResource(int company, int saleCode);
	Flyweight * GetFly(Key & clsKey);

private:
	void	Clear();

private:
	typedef std::map< Key, Flyweight * >	DATATREE;
	DATATREE	clsFlyTree;
};



class CommonResource
{
public:
	CommonResource();
	virtual ~CommonResource();

	bool LoadResource();
	CommonData::Flyweight * GetFly(User * pUser, CommonData::Key & clsKey);

	int		GetLimitLevel(User * pUser);

private:
	CommonData * pCommonAndroid;
	CommonData * pCommonIOS;
};

} /*NResource*/ } /* namespace ProjectZ */

#endif /* COMMONRESOURCE_H_ */
